<template>
  <a-modal :open="open" width="640px" title="核算" centered ok-text="核算" @ok="onOk" @cancel="onCancel">
    <a-form class="form-style-flex" name="validate_other" :model="formState">
      <a-form-item label="核算月度" class="w-1/2">
        {{ formState.month }}
      </a-form-item>
      <a-form-item label="核算人" class="w-1/2">
        {{ empName }}
      </a-form-item>
      <a-form-item label="备注" class="w-full mb-3">
        <a-textarea v-model:value="formState.memo" :rows="5" placeholder="请输入" />
      </a-form-item>
    </a-form>
  </a-modal>
</template>
<script setup>
import { ref, watch } from 'vue'
import { message } from 'ant-design-vue'
import { post } from '@/utils/request'
import useUserStore from '@/store/user'

const { empName } = useUserStore()
const emit = defineEmits(['update:open', 'success'])
const clickType = ref(false)

const props = defineProps({
  open: {
    type: Boolean,
    default: false
  },
  rowData: {
    type: Object,
    default: () => ({})
  },
  title: {
    type: String,
    default: ''
  }
})

const formState = ref(null)

watch(
  () => props.open,
  (val) => {
    if (val) {
      if (props.rowData?.month) {
        formState.value = { ...props.rowData }
      }
    }
  }
)
const onOk = async () => {
  if (clickType.value) return message.warning('正在处理')
  clickType.value = true
  const res = await post('/materials/comprehenive/doMonthWeightedAverage', formState.value)

  if (res.code === 0) {
    message.success(res.msg)

    emit('success')
    onCancel()
  } else {
    message.error(res.msg)
  }
  clickType.value = false
}

const onCancel = () => {
  emit('update:open', false)
}
</script>
<style lang="less" scoped></style>
